Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to run pg_repack by non-superuser #431

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

za-arthur
Copy link
Collaborator

@za-arthur za-arthur commented Oct 30, 2024

The option --no-superuser-check allows to by-pass the check if the user is a superuser. That was done for users which run pg_repack on Amazon, where users cannot run it as a superuser.
The problem is that the option --no-superuser-check works only on the CLI level, skipping the check only by the pg_repack client. But there are also checks done by the extension functions exported to SQL.

The PR removes the check that the user is a superuser from functions repack_trigger() and repack_apply(). That check is redundant since queries executed by that functions can be executed by a user manually. Moreover repack_trigger() is a SECURITY DEFINER function, which means that it is executed with superuser privileges (pg_repack extension can be created only by superuser).

The PR changes privilege check in functions repack_swap(), repack_drop() and repack_index_swap(). Now that functions can be run by an owner of a table. That check is necessary since _swap functions swap relfilenodes on pg_class system catalog table. repack_drop() acquires ACCESS EXCLUSIVE lock and therefore it also requires privilege check.

Additionally I cherry-picked the commit 326b6e1 from the PR #427. Otherwise pg_repack will fall with segmentation fault in case of lack of permissions.

Relevant issues:

Fixed the bug that segmentation fault occurs when default_transaction_read_only is turned on during repacking. bug: #426
@za-arthur za-arthur force-pushed the issue223_no_superuser_check branch from 14c784f to 139895a Compare October 30, 2024 14:54
@andreasscherbaum
Copy link
Collaborator

Ah, nice, comes with additional tests. I like that.

@za-arthur za-arthur force-pushed the issue223_no_superuser_check branch from 139895a to ecbc587 Compare November 1, 2024 11:23
Now everybody how has access to repack_trigger() and repack_apply() and
relevant objects can call that functions.

Functions repack_swap(), repack_drop() and repack_index_swap() can be
called by superuser and owners of a table.

Cherry-pick the commit 326b6e1 to not cause segmentation fault when
using -k option and not having enough permissions.
@za-arthur za-arthur force-pushed the issue223_no_superuser_check branch from ecbc587 to a692b14 Compare November 1, 2024 13:33
@za-arthur
Copy link
Collaborator Author

I'd like to merge the PR this week if no objections.

@za-arthur za-arthur merged commit 85b64c6 into master Nov 7, 2024
20 checks passed
@za-arthur za-arthur deleted the issue223_no_superuser_check branch November 7, 2024 13:21
za-arthur added a commit to supabase/postgres that referenced this pull request Nov 7, 2024
New version allows to run pg_repack by a non-superuser.
PR on pg_repack repo:
reorg/pg_repack#431
za-arthur added a commit to supabase/postgres that referenced this pull request Nov 7, 2024
New version allows to run pg_repack by a non-superuser.
PR on pg_repack repo:
reorg/pg_repack#431
@ololobus
Copy link

@za-arthur thanks for this work! Any plans on tagging a 1.5.2 release with this change? I see it's already set to 1.5.2 here

"version": "1.5.2",
and you mentioned this in Supabase repo, but I don't see the right tag https://github.com/reorg/pg_repack/tags

tristan957 added a commit to neondatabase/neon that referenced this pull request Dec 11, 2024
Our solutions engineers and some customers would like to have this
extension available. We are using a commit instead of a tagged release
because pg_repack maintainers have not tagged a release which contains
the commit that allows us to run pg_repack as a non-superuser.

Link: reorg/pg_repack#431 (comment)
Signed-off-by: Tristan Partin <[email protected]>
tristan957 added a commit to neondatabase/neon that referenced this pull request Dec 11, 2024
Our solutions engineers and some customers would like to have this
extension available. We are using a commit instead of a tagged release
because pg_repack maintainers have not tagged a release which contains
the commit that allows us to run pg_repack as a non-superuser.

Closes: neondatabase/cloud#18890
Link: reorg/pg_repack#431 (comment)
Signed-off-by: Tristan Partin <[email protected]>
tristan957 added a commit to neondatabase/neon that referenced this pull request Dec 11, 2024
Our solutions engineers and some customers would like to have this
extension available. We are using a commit instead of a tagged release
because pg_repack maintainers have not tagged a release which contains
the commit that allows us to run pg_repack as a non-superuser.

Closes: neondatabase/cloud#18890
Link: reorg/pg_repack#431 (comment)
Signed-off-by: Tristan Partin <[email protected]>
@za-arthur
Copy link
Collaborator Author

@ololobus new version was released https://github.com/reorg/pg_repack/tree/ver_1.5.2. Although the website wasn't updated yet.

@ololobus
Copy link

@za-arthur thanks! The git tag is what I actually needed

tristan957 added a commit to neondatabase/neon that referenced this pull request Dec 16, 2024
Our solutions engineers and some customers would like to have this
extension available. We are using a commit instead of a tagged release
because pg_repack maintainers have not tagged a release which contains
the commit that allows us to run pg_repack as a non-superuser.

Closes: neondatabase/cloud#18890
Link: reorg/pg_repack#431 (comment)
Signed-off-by: Tristan Partin <[email protected]>
tristan957 added a commit to neondatabase/neon that referenced this pull request Dec 17, 2024
Our solutions engineers and some customers would like to have this
extension available. We are using a commit instead of a tagged release
because pg_repack maintainers have not tagged a release which contains
the commit that allows us to run pg_repack as a non-superuser.

Closes: neondatabase/cloud#18890
Link: reorg/pg_repack#431 (comment)
Signed-off-by: Tristan Partin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants